package cn.kgc.tangcco.anyang.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageInfo;

import cn.kgc.tangcco.anyang.mapper.ClazzMapper;
import cn.kgc.tangcco.anyang.pojo.Clazz;
import cn.kgc.tangcco.anyang.service.ClazzService;

@Service("clazzService")
public class ClazzServiceImpl implements ClazzService {

	@Autowired
	private ClazzMapper clazzMapper;

	@Override
	public Map<String, Object> addClazz(Clazz clazz) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("errorCode", "1");
		map.put("errorMsg", "");
		// 调用持久层方法
		int status = clazzMapper.insertClazz(clazz);
		if (status > 0) {
			map.put("errorCode", "0");
			map.put("errorMsg", "OK");
		}
		return map;
	}

	@Override
	public Map<String, Object> addClazzs(List<Clazz> list) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("errorCode", "1");
		map.put("errorMsg", "");
		// 调用持久层方法
		int status = clazzMapper.insertClazzs(list);
		if (status > 0) {
			map.put("errorCode", "0");
			map.put("errorMsg", "OK");
		}
		return map;
	}

	@Override
	public Map<String, Object> updateClazz(Clazz clazz) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("errorCode", "1");
		map.put("errorMsg", "");
		// 调用持久层方法
		int status = clazzMapper.updateClazz(clazz);
		if (status > 0) {
			map.put("errorCode", "0");
			map.put("errorMsg", "OK");
		}
		return map;
	}

	@Override
	public Map<String, Object> removeClazz(Integer id) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("errorCode", "1");
		map.put("errorMsg", "");
		// 调用持久层方法
		int status = clazzMapper.deleteClazz(id);
		if (status > 0) {
			map.put("errorCode", "0");
			map.put("errorMsg", "OK");
		}
		return map;
	}

	@Override
	public Map<String, Object> queryClazzs(Map<String, Object> queryParams) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("errorCode", "1");
		map.put("errorMsg", "");
		// 调用持久层方法
		List<Clazz> clazzs = clazzMapper.selectClazzs(queryParams);
		if (clazzs != null && clazzs.size() > 0) {
			map.put("errorCode", "0");
			map.put("errorMsg", "OK");
			map.put("data", clazzs);
		}else if (clazzs.size() == 0) {
			map.put("errorCode", "2");
			map.put("errorMsg", "OK");
		}
		return map;
	}

	@Override
	public Map<String, Object> getClazzById(Integer id) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("errorCode", "1");
		map.put("errorMsg", "");
		// 调用持久层方法
		Clazz clazz = clazzMapper.selectClazzById(id);
		if (clazz != null) {
			map.put("errorCode", "0");
			map.put("errorMsg", "OK");
			map.put("data", clazz);
		}
		return map;
	}

}
